package com.itheima.a04mytreemap;

import java.util.Comparator;
import java.util.TreeMap;
import java.util.function.BiConsumer;

public class A03_TreeMapDemo3 {
    public static void main(String[] args) {
        String s="aababcabcdabcde";

        //创建集合
        TreeMap<Character,Integer> tm=new TreeMap<>(new Comparator<Character>() {
            @Override
            public int compare(Character o1, Character o2) {
                return o2-o1;
            }
        });

        for(int i=0;i<s.length();i++){
            char c=s.charAt(i);
            if(tm.containsKey(c)){
                int count=tm.get(c);
                count++;
                tm.put(c,count);
            }else{
                tm.put(c,1);
            }
        }

        //System.out.println(tm);
        StringBuilder sb=new StringBuilder();
        tm.forEach(new BiConsumer<Character, Integer>() {
            @Override
            public void accept(Character character, Integer integer) {
                sb.append(character).append("(").append(integer).append(")");
            }
        });

        System.out.println(sb);
    }
}
